package com.cgg.stock.transaction.controller;

import com.cgg.stock.common.pojo.Order;
import com.cgg.stock.common.pojo.TradeOrder;
import com.cgg.stock.common.util.ResponseData;
import com.cgg.stock.common.util.ResponseDataUtil;
import com.cgg.stock.transaction.service.ITransactionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api("撮合交易控制器")
@RequestMapping("match")
@Slf4j
public class TransactionController {
    @Autowired
    private ITransactionService ITransactionService;

    @ApiOperation("卖出撮合")
    @PostMapping("/matchSell")
    public ResponseData matchSell(@RequestBody Order order) throws Exception {
        List<TradeOrder> tradeOrders = ITransactionService.processLimitSell(order);
        log.info("撮合成功的订单:{}",tradeOrders);
        return ResponseDataUtil.buildOk("开始撮合");
    }

    @ApiOperation("买入撮合")
    @PostMapping("/matchBuy")
    public ResponseData matchBuy(@RequestBody Order order) throws Exception {
        List<TradeOrder> tradeOrders = ITransactionService.processLimitBuy(order);
        log.info("撮合成功的订单:{}",tradeOrders);
        return ResponseDataUtil.buildOk("开始撮合");
    }
}
